package a630wj.recycleview630wj.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import a630wj.recycleview630wj.R;
import a630wj.recycleview630wj.adapter.VideoAdapter;
import a630wj.recycleview630wj.bean.VideoBean;
import a630wj.recycleview630wj.iface.VideoListener;
import a630wj.recycleview630wj.model.VideoModel;

/**
 * Created by weijie on 2017/6/6.
 */

public class VideoFragment extends Fragment {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private VideoAdapter myadapter;
    private List<VideoBean> list=null;
    private View view=null;
    private Context context;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view =inflater.inflate(R.layout.videofragment,container,false);
        context=view.getContext();

        initRecyclerView();
        VideoModel videoModer =new VideoModel();
        VideoModel.getResultList("video",2,"oeau24oa0naqqeglc0ec7j2bp0",videolistener);
        return view;
    }
    VideoListener videolistener = new VideoListener() {

        @Override
        public void onResponse(List<VideoBean> listbean) {
            
            list=listbean;
            myadapter.setList(list);

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "fail:" + msg, Toast.LENGTH_SHORT).show();
        }
    };

    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rv_article1);

        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(context);
        //设置布局
        recyclerView.setLayoutManager(layoutManager);
        //设置item的高度
        recyclerView.setHasFixedSize(true);
        //创建适配器
//        list=getData();
        myadapter= new VideoAdapter(context);

        myadapter.setList(list);

        recyclerView.setAdapter(myadapter);

    }
}
